package io;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.util.Scanner;

/*
在本程序启动Java虚拟机运行另一个Java程序，并向另一个Java程序输入数据
 */
public class WriterToProcess {

    public static void main(String[] args) {
        try {
            Process process = Runtime.getRuntime().exec("java ReadStandard.class");
            PrintStream printStream = new PrintStream(process.getOutputStream());
            printStream.print("普通字符串");
            printStream.print(new WriterToProcess());
            printStream.close();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {

        }
    }
}
class ReadStandard {
    public static void main(String[] args) throws FileNotFoundException {
        Scanner scanner = new Scanner(System.in);
        PrintStream printStream = new PrintStream(new FileOutputStream("out.txt"));
        scanner.useDelimiter("\n");
        while (scanner.hasNext()) {
            printStream.println("键盘输入的内容： " + scanner.next());
        }
        printStream.close();
    }
}
